package main

import (
	"fmt"
	"sync"
)

var ticket=100
var lock sync.Mutex
var wg sync.WaitGroup
func sellticket()  {
	for ticket>0{
       lock.Lock()
       if(ticket>0) {
		   ticket--
		   fmt.Println("票还有：", ticket)
		   lock.Unlock()
		   wg.Done()
	   }else{
	   	lock.Unlock()
	   	break
	   }
	}

}
func main() {
	wg.Add(100)
	for i:=0;i<10;i++{
		go sellticket()
	}
	wg.Wait()
	fmt.Println("票卖完了")
}
